#define quickread
#ifdef quickread
#include <cstdio> 
template <typename T>
inline void read(T& x)
{
    int c=getchar(), f=1; x=0;
    while(c<'0'||'9'<c) {if(c=='-') f=-1; c=getchar();}
    while('0'<=c&&c<='9') 
        x=(x<<3)+(x<<1)+c-'0', c=getchar();
    x*=f;
}
template <typename T>
inline void quickwrite(T x)
{
    if(x<0) putchar('-'), x*=-1;
    if(x>=10) quickwrite(x/10);
    putchar(x%10+'0');
}
#else 
#include <iostream>
#endif
using namespace std;
#define DEBUG
#define int long long
int Q, k;
int f[200];
int S[200][5];
int s(int x)
{
    int ans=0;
    while(x) ans+=x%10, x/=10;
    return ans;
}


void init()
{
    read(Q), read(k);
    for(int i=1; i<=162; i++)
    {
        S[i][0]=i; S[i][1]=s(S[i][0]);
        S[i][2]=s(S[i][1]);
        if(k<=3)
            for(int j=0; j<k; j++) f[i]+=S[i][j];
        else f[i]=S[i][0]+S[i][1]+S[i][2]+1ll*(k-3)*S[i][2];
    }
}

void solve()
{
    init();
    while(Q--)
    {
        int m, ans=0; read(m);
        for(int i=1; i<=162; i++)
            if(s(m-f[i])==i) ans++;
        quickwrite(ans); puts("");
    }
}

// #undef DEBUG
signed main()
{
    #ifdef DEBUG
        freopen("../in.txt", "r", stdin);
        // freopen("../out.txt", "w", stdout);
    #endif
    #ifndef quickread
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    #endif

    int T=1; //scanf("%d", &T);
    while(T--) 
    {
        solve();
    }
    return 0;
}
